package com.coocaa.ops.admin.v1.cornericon.biz.impl;

import com.coocaa.ops.admin.v1.cornericon.biz.ICornerIconBiz;
import com.coocaa.ops.admin.v1.cornericon.mapper.IGlobalCornerIconMapper;
import com.coocaa.ops.common.core.base.BaseBizImpl;
import com.coocaa.ops.common.core.base.mybatis.UpdateTemplate;
import com.coocaa.ops.common.core.biz.cornericon.entity.GlobalCornerIconEntity;
import com.coocaa.ops.common.tool.date.DateUtil;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * @author bijiahao
 * @date : 2018/8/17.
 * @description
 */
@Service
public class CornerIconBizImpl extends BaseBizImpl<IGlobalCornerIconMapper, GlobalCornerIconEntity> implements ICornerIconBiz {

    @Override
    public GlobalCornerIconEntity add(GlobalCornerIconEntity entity) {
        Date date = DateUtil.getCurDate();
        entity.setCreatedDate(date);
        entity.setLastUpdateDate(date);
        getMapper().insert(entity);
        return entity;
    }

    @Override
    public boolean isCornerIsUsedByCurrentPanel(Integer cornerIconId) {
        Integer count =  getMapper().checkCornerIsUsedByCurrentPanel(cornerIconId);
        return  count != null && count > 0;
    }


    /**
     * 批量 逻辑删除-角标
     *
     * @param ids
     */
    @Override
    public void logicDelBatchCornerByIds(Integer[] ids) {
        UpdateTemplate<GlobalCornerIconEntity> wrapper = new UpdateTemplate<>();
        wrapper.lambda().in(GlobalCornerIconEntity::getId, ids);
        GlobalCornerIconEntity update = new GlobalCornerIconEntity();
        update.setFlag(0);
        getMapper().update(update, wrapper);
    }

}
